﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Data;
using System.Data.SqlClient;

/// <summary>
/// Descripción breve de WS_MaeHoteles
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// Para permitir que se llame a este servicio Web desde un script, usando ASP.NET AJAX, quite la marca de comentario de la línea siguiente. 
// [System.Web.Script.Services.ScriptService]
public class WS_MaeHoteles : System.Web.Services.WebService {

    public WS_MaeHoteles () {

        //Eliminar la marca de comentario de la línea siguiente si utiliza los componentes diseñados 
        //InitializeComponent(); 
    }

    
    string cadena = "server=HENRY-PC\\SQLEXPRESS;database=Silvana01;Integrated Security=SSPI";
    //string cadena = "server=.;database=Silvana01;Integrated Security=SSPI";

    SqlConnection cnx = new SqlConnection();
    SqlCommand cmd = new SqlCommand();
    DataSet dts = new DataSet();
    SqlDataAdapter ada = new SqlDataAdapter();

    [WebMethod]
    public DataSet ListarHoteles()
    {

        try
        {
            dts.Clear();
            cnx.ConnectionString = cadena;
            cmd.Connection = cnx;
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.CommandText = "usp_ListarHoteles";
            ada = new SqlDataAdapter(cmd);
            ada.Fill(dts, "ListaHoteles");

        }
        catch (Exception ex)
        {
            throw new Exception(ex.Message);
        }

        return dts;
    }

    [WebMethod]
    public DataSet ConsultarHotelesxGrupo(float nFecDesde, float nFecHasta)
    {

        try
        {
            dts.Clear();
            cnx.ConnectionString = cadena;
            cmd.Connection = cnx;
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.CommandText = "usp_ConsultarHotelesxGrupo";
            cmd.Parameters.Add(new SqlParameter("@vnfecdesde", SqlDbType.Float));
            cmd.Parameters.Add(new SqlParameter("@vnfechasta", SqlDbType.Float));
            cmd.Parameters["@vnfecdesde"].Value = nFecDesde;
            cmd.Parameters["@vnfechasta"].Value = nFecHasta;
            ada = new SqlDataAdapter(cmd);
            ada.Fill(dts, "ConsultaHotelesxGrupo");

        }
        catch (Exception ex)
        {
            throw new Exception(ex.Message);
        }

        return dts;
    }

    [WebMethod]
    public bool ActualizarHoteles(string vscodhotel, string vsdeshotel, string vsdirhotel, string vscodlocal, string vsdeslocal, string vsemail, string vstelef, string vsdesrepre)
    {

        bool exito = false;
        SqlCommand cmd = new SqlCommand();

        //Se configura el comando: Store Procedure
        cnx.ConnectionString = cadena;
        cmd.Connection = cnx;
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.CommandText = "usp_ActualizarHoteles";

        cmd.Parameters.Add(new SqlParameter("@vscodhotel", SqlDbType.Char, 5));
        cmd.Parameters["@vscodhotel"].Value = vscodhotel;
        cmd.Parameters.Add(new SqlParameter("@vsdeshotel", SqlDbType.Char, 80));
        cmd.Parameters["@vsdeshotel"].Value = vsdeshotel;
        cmd.Parameters.Add(new SqlParameter("@vsdirhotel", SqlDbType.Char, 80));
        cmd.Parameters["@vsdirhotel"].Value = vsdirhotel;
        cmd.Parameters.Add(new SqlParameter("@vscodlocal", SqlDbType.Char, 3));
        cmd.Parameters["@vscodlocal"].Value = vscodlocal;
        cmd.Parameters.Add(new SqlParameter("@vsdeslocal", SqlDbType.Char, 50));
        cmd.Parameters["@vsdeslocal"].Value = vsdeslocal;
        cmd.Parameters.Add(new SqlParameter("@vsemail", SqlDbType.Char, 50));
        cmd.Parameters["@vsemail"].Value = vsemail;
        cmd.Parameters.Add(new SqlParameter("@vstelef", SqlDbType.Char, 50));
        cmd.Parameters["@vstelef"].Value = vstelef;
        cmd.Parameters.Add(new SqlParameter("@vsdesrepre", SqlDbType.Char, 50));
        cmd.Parameters["@vsdesrepre"].Value = vsdesrepre;
        try
        {
            cnx.Open();
            cmd.ExecuteNonQuery();
            cnx.Close();
            exito = true;
        }
        catch (Exception ex)
        {
            throw new Exception(ex.Message);
        }
        return exito;
    }

    [WebMethod]
    public DataSet ConsultarEstadisticaxHoteles(float nFecDesde, float nFecHasta)
    {

        try
        {
            dts.Clear();
            cnx.ConnectionString = cadena;
            cmd.Connection = cnx;
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.CommandText = "usp_ConsultarEstadisticaxHoteles";
            cmd.Parameters.Add(new SqlParameter("@vnfecdesde", SqlDbType.Float));
            cmd.Parameters.Add(new SqlParameter("@vnfechasta", SqlDbType.Float));
            cmd.Parameters["@vnfecdesde"].Value = nFecDesde;
            cmd.Parameters["@vnfechasta"].Value = nFecHasta;
            ada = new SqlDataAdapter(cmd);
            ada.Fill(dts, "EstadisticaxHoteles");

        }
        catch (Exception ex)
        {
            throw new Exception(ex.Message);
        }

        return dts;
    }

}
